<template>
  <a-form-model :model="form" :label-col="labelCol" :wrapper-col="wrapperCol">
    <a-form-model-item label="文章类型">
      <a-select v-model="form.type" placeholder="请选择文章类型">
        <a-select-option v-for="item in types" :key="item.id" :value="item.id">{{item.typeName}}</a-select-option>
      </a-select>
    </a-form-model-item>
    <a-form-model-item label="文章标题">
      <a-input v-model="form.title" />
    </a-form-model-item>
    <a-form-model-item label="文章简介">
      <a-input v-model="form.introduce" />
    </a-form-model-item>
    <a-form-model-item label="文章详情">
      <mavon-editor class="editor" v-model="form.article_con" />
    </a-form-model-item>
    <a-form-model-item :wrapper-col="{ span: 14, offset: 4 }">
      <a-button type="primary" @click="onSubmit">添加</a-button>
      <a-button style="margin-left: 10px;">取消</a-button>
    </a-form-model-item>
  </a-form-model>
</template>
<script>
import { getArticleType, addArticle } from '../../api/manage.js'
export default {
  data () {
    return {
      labelCol: { span: 4 },
      wrapperCol: { span: 14 },
      form: {},
      types: []
    }
  },
  mounted () {
    this.initArticleType()
  },
  methods: {
    async onSubmit () {
      const res = await addArticle(this.form)
      console.log(res)
      if (res.status === 200) {
        this.$notification.open({
          message: '提示',
          description: '添加成功',
          duration: 0
        })
        this.$router.push('/article/articlelist')
      } else {
        this.$notification.open({
          message: '提示',
          description: '添加失败',
          duration: 0
        })
      }
    },
    // 初始化文章类型列表
    async initArticleType () {
      const res = await getArticleType()
      this.types = res.data
    }
  }
}
</script>

<style lang="scss" scoped>
.editor {
  height: 400px;
}
</style>
